package cn.doitedu;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;
import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.List;
import java.util.stream.Collectors;

public class TokenizerStrUDF extends UDF {

    public String evaluate(String keyword){

        // 速溶咖啡
        List<Term> segment = HanLP.segment(keyword);
        List<String> filtered = segment.stream().map(term -> term.word).filter(w -> w.length() > 1).collect(Collectors.toList());

        StringBuilder sb = new StringBuilder();
        for (String w : filtered) {
            sb.append(w).append("|");
        }

        String res = sb.substring(0, sb.length() - 1);

        return res;
    }

}
